package vip.zhenzicheng.algorithm.util;

import java.util.Arrays;

/**
 * 数组工具类工具类
 *
 * @author zhenzicheng
 * @date: 2022-05-17 14:01
 */
public class ArrayUtils {

  /**
   * 对数器，生成随机长度的,随机值数组
   */
  public static int[] getRandomArray(int maxLength, int maxValue) {
    int len = (int) (Math.random() * maxLength);
    int[] ans = new int[len];
    for (int i = 0; i < len; i++) {
      ans[i] = (int) (Math.random() * maxValue);
    }
    return ans;
  }

  public static void swap(int[] arr, int i, int j) {
    if (arr == null || arr.length == 0) {
      return;
    }

    int temp = arr[i];
    arr[i] = arr[j];
    arr[j] = temp;
  }

  public static void printArray(int[] arr) {
    System.out.println(Arrays.toString(arr));
  }

}
